home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / lispref.info-22.z / lispref.info-22
Encoding:
GNU Info File  |  1998-05-21  |  48.9 KB  |  1,232 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo version
  2. 1.68 from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
  12. Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
  13. Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
  14.  
  15.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  16. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  17. Copyright (C) 1995, 1996 Ben Wing.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that the
  25. entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Foundation.
  32.  
  33.    Permission is granted to copy and distribute modified versions of
  34. this manual under the conditions for verbatim copying, provided also
  35. that the section entitled "GNU General Public License" is included
  36. exactly as in the original, and provided that the entire resulting
  37. derived work is distributed under the terms of a permission notice
  38. identical to this one.
  39.  
  40.    Permission is granted to copy and distribute translations of this
  41. manual into another language, under the above conditions for modified
  42. versions, except that the section entitled "GNU General Public License"
  43. may be included in a translation approved by the Free Software
  44. Foundation instead of in the original English.
  45.  
  46. 
  47. File: lispref.info,  Node: Testing Accessibility,  Next: Kinds of Files,  Up: Information about Files
  48.  
  49. Testing Accessibility
  50. ---------------------
  51.  
  52.    These functions test for permission to access a file in specific
  53. ways.
  54.  
  55.  - Function: file-exists-p FILENAME
  56.      This function returns `t' if a file named FILENAME appears to
  57.      exist.  This does not mean you can necessarily read the file, only
  58.      that you can find out its attributes.  (On Unix, this is true if
  59.      the file exists and you have execute permission on the containing
  60.      directories, regardless of the protection of the file itself.)
  61.  
  62.      If the file does not exist, or if fascist access control policies
  63.      prevent you from finding the attributes of the file, this function
  64.      returns `nil'.
  65.  
  66.  - Function: file-readable-p FILENAME
  67.      This function returns `t' if a file named FILENAME exists and you
  68.      can read it.  It returns `nil' otherwise.
  69.  
  70.           (file-readable-p "files.texi")
  71.                => t
  72.           (file-exists-p "/usr/spool/mqueue")
  73.                => t
  74.           (file-readable-p "/usr/spool/mqueue")
  75.                => nil
  76.  
  77.  - Function: file-executable-p FILENAME
  78.      This function returns `t' if a file named FILENAME exists and you
  79.      can execute it.  It returns `nil' otherwise.  If the file is a
  80.      directory, execute permission means you can check the existence and
  81.      attributes of files inside the directory, and open those files if
  82.      their modes permit.
  83.  
  84.  - Function: file-writable-p FILENAME
  85.      This function returns `t' if the file FILENAME can be written or
  86.      created by you, and `nil' otherwise.  A file is writable if the
  87.      file exists and you can write it.  It is creatable if it does not
  88.      exist, but the specified directory does exist and you can write in
  89.      that directory.
  90.  
  91.      In the third example below, `foo' is not writable because the
  92.      parent directory does not exist, even though the user could create
  93.      such a directory.
  94.  
  95.           (file-writable-p "~/foo")
  96.                => t
  97.           (file-writable-p "/foo")
  98.                => nil
  99.           (file-writable-p "~/no-such-dir/foo")
  100.                => nil
  101.  
  102.  - Function: file-accessible-directory-p DIRNAME
  103.      This function returns `t' if you have permission to open existing
  104.      files in the directory whose name as a file is DIRNAME; otherwise
  105.      (or if there is no such directory), it returns `nil'.  The value
  106.      of DIRNAME may be either a directory name or the file name of a
  107.      directory.
  108.  
  109.      Example: after the following,
  110.  
  111.           (file-accessible-directory-p "/foo")
  112.                => nil
  113.  
  114.      we can deduce that any attempt to read a file in `/foo/' will give
  115.      an error.
  116.  
  117.  - Function: file-ownership-preserved-p FILENAME
  118.      This function returns `t' if deleting the file FILENAME and then
  119.      creating it anew would keep the file's owner unchanged.
  120.  
  121.  - Function: file-newer-than-file-p FILENAME1 FILENAME2
  122.      This function returns `t' if the file FILENAME1 is newer than file
  123.      FILENAME2.  If FILENAME1 does not exist, it returns `nil'.  If
  124.      FILENAME2 does not exist, it returns `t'.
  125.  
  126.      In the following example, assume that the file `aug-19' was written
  127.      on the 19th, `aug-20' was written on the 20th, and the file
  128.      `no-file' doesn't exist at all.
  129.  
  130.           (file-newer-than-file-p "aug-19" "aug-20")
  131.                => nil
  132.           (file-newer-than-file-p "aug-20" "aug-19")
  133.                => t
  134.           (file-newer-than-file-p "aug-19" "no-file")
  135.                => t
  136.           (file-newer-than-file-p "no-file" "aug-19")
  137.                => nil
  138.  
  139.      You can use `file-attributes' to get a file's last modification
  140.      time as a list of two numbers.  *Note File Attributes::.
  141.  
  142. 
  143. File: lispref.info,  Node: Kinds of Files,  Next: Truenames,  Prev: Testing Accessibility,  Up: Information about Files
  144.  
  145. Distinguishing Kinds of Files
  146. -----------------------------
  147.  
  148.    This section describes how to distinguish various kinds of files,
  149. such as directories, symbolic links, and ordinary files.
  150.  
  151.  - Function: file-symlink-p FILENAME
  152.      If the file FILENAME is a symbolic link, the `file-symlink-p'
  153.      function returns the file name to which it is linked.  This may be
  154.      the name of a text file, a directory, or even another symbolic
  155.      link, or it may be a nonexistent file name.
  156.  
  157.      If the file FILENAME is not a symbolic link (or there is no such
  158.      file), `file-symlink-p' returns `nil'.
  159.  
  160.           (file-symlink-p "foo")
  161.                => nil
  162.           (file-symlink-p "sym-link")
  163.                => "foo"
  164.           (file-symlink-p "sym-link2")
  165.                => "sym-link"
  166.           (file-symlink-p "/bin")
  167.                => "/pub/bin"
  168.  
  169.  
  170.  - Function: file-directory-p FILENAME
  171.      This function returns `t' if FILENAME is the name of an existing
  172.      directory, `nil' otherwise.
  173.  
  174.           (file-directory-p "~rms")
  175.                => t
  176.           (file-directory-p "~rms/lewis/files.texi")
  177.                => nil
  178.           (file-directory-p "~rms/lewis/no-such-file")
  179.                => nil
  180.           (file-directory-p "$HOME")
  181.                => nil
  182.           (file-directory-p
  183.            (substitute-in-file-name "$HOME"))
  184.                => t
  185.  
  186.  - Function: file-regular-p FILENAME
  187.      This function returns `t' if the file FILENAME exists and is a
  188.      regular file (not a directory, symbolic link, named pipe,
  189.      terminal, or other I/O device).
  190.  
  191. 
  192. File: lispref.info,  Node: Truenames,  Next: File Attributes,  Prev: Kinds of Files,  Up: Information about Files
  193.  
  194. Truenames
  195. ---------
  196.  
  197.    The "truename" of a file is the name that you get by following
  198. symbolic links until none remain, then expanding to get rid of `.'  and
  199. `..' as components.  Strictly speaking, a file need not have a unique
  200. truename; the number of distinct truenames a file has is equal to the
  201. number of hard links to the file.  However, truenames are useful
  202. because they eliminate symbolic links as a cause of name variation.
  203.  
  204.  - Function: file-truename FILENAME &optional DEFAULT
  205.      The function `file-truename' returns the true name of the file
  206.      FILENAME.  This is the name that you get by following symbolic
  207.      links until none remain.
  208.  
  209.      If the filename is relative, DEFAULT is the directory to start
  210.      with.  If DEFAULT is `nil' or missing, the current buffer's value
  211.      of `default-directory' is used.
  212.  
  213.    *Note Buffer File Name::, for related information.
  214.  
  215. 
  216. File: lispref.info,  Node: File Attributes,  Prev: Truenames,  Up: Information about Files
  217.  
  218. Other Information about Files
  219. -----------------------------
  220.  
  221.    This section describes the functions for getting detailed information
  222. about a file, other than its contents.  This information includes the
  223. mode bits that control access permission, the owner and group numbers,
  224. the number of names, the inode number, the size, and the times of access
  225. and modification.
  226.  
  227.  - Function: file-modes FILENAME
  228.      This function returns the mode bits of FILENAME, as an integer.
  229.      The mode bits are also called the file permissions, and they
  230.      specify access control in the usual Unix fashion.  If the
  231.      low-order bit is 1, then the file is executable by all users, if
  232.      the second-lowest-order bit is 1, then the file is writable by all
  233.      users, etc.
  234.  
  235.      The highest value returnable is 4095 (7777 octal), meaning that
  236.      everyone has read, write, and execute permission, that the SUID bit
  237.      is set for both others and group, and that the sticky bit is set.
  238.  
  239.           (file-modes "~/junk/diffs")
  240.                => 492               ; Decimal integer.
  241.           (format "%o" 492)
  242.                => "754"             ; Convert to octal.
  243.           
  244.           (set-file-modes "~/junk/diffs" 438)
  245.                => nil
  246.           
  247.           (format "%o" 438)
  248.                => "666"             ; Convert to octal.
  249.           
  250.           % ls -l diffs
  251.             -rw-rw-rw-  1 lewis 0 3063 Oct 30 16:00 diffs
  252.  
  253.  - Function: file-nlinks FILENAME
  254.      This functions returns the number of names (i.e., hard links) that
  255.      file FILENAME has.  If the file does not exist, then this function
  256.      returns `nil'.  Note that symbolic links have no effect on this
  257.      function, because they are not considered to be names of the files
  258.      they link to.
  259.  
  260.           % ls -l foo*
  261.           -rw-rw-rw-  2 rms       4 Aug 19 01:27 foo
  262.           -rw-rw-rw-  2 rms       4 Aug 19 01:27 foo1
  263.           
  264.           (file-nlinks "foo")
  265.                => 2
  266.           (file-nlinks "doesnt-exist")
  267.                => nil
  268.  
  269.  - Function: file-attributes FILENAME
  270.      This function returns a list of attributes of file FILENAME.  If
  271.      the specified file cannot be opened, it returns `nil'.
  272.  
  273.      The elements of the list, in order, are:
  274.  
  275.        0. `t' for a directory, a string for a symbolic link (the name
  276.           linked to), or `nil' for a text file.
  277.  
  278.        1. The number of names the file has.  Alternate names, also
  279.           known as hard links, can be created by using the
  280.           `add-name-to-file' function (*note Changing File
  281.           Attributes::.).
  282.  
  283.        2. The file's UID.
  284.  
  285.        3. The file's GID.
  286.  
  287.        4. The time of last access, as a list of two integers.  The
  288.           first integer has the high-order 16 bits of time, the second
  289.           has the low 16 bits.  (This is similar to the value of
  290.           `current-time'; see *Note Time of Day::.)
  291.  
  292.        5. The time of last modification as a list of two integers (as
  293.           above).
  294.  
  295.        6. The time of last status change as a list of two integers (as
  296.           above).
  297.  
  298.        7. The size of the file in bytes.
  299.  
  300.        8. The file's modes, as a string of ten letters or dashes, as in
  301.           `ls -l'.
  302.  
  303.        9. `t' if the file's GID would change if file were deleted and
  304.           recreated; `nil' otherwise.
  305.  
  306.       10. The file's inode number.
  307.  
  308.       11. The file system number of the file system that the file is
  309.           in.  This element and the file's inode number together give
  310.           enough information to distinguish any two files on the
  311.           system--no two files can have the same values for both of
  312.           these numbers.
  313.  
  314.      For example, here are the file attributes for `files.texi':
  315.  
  316.           (file-attributes "files.texi")
  317.                =>  (nil
  318.                     1
  319.                     2235
  320.                     75
  321.                     (8489 20284)
  322.                     (8489 20284)
  323.                     (8489 20285)
  324.                     14906
  325.                     "-rw-rw-rw-"
  326.                     nil
  327.                     129500
  328.                     -32252)
  329.  
  330.      and here is how the result is interpreted:
  331.  
  332.     `nil'
  333.           is neither a directory nor a symbolic link.
  334.  
  335.     `1'
  336.           has only one name (the name `files.texi' in the current
  337.           default directory).
  338.  
  339.     `2235'
  340.           is owned by the user with UID 2235.
  341.  
  342.     `75'
  343.           is in the group with GID 75.
  344.  
  345.     `(8489 20284)'
  346.           was last accessed on Aug 19 00:09. Use `format-time-string' to
  347.           ! convert this number into a time string.  *Note Time
  348.           Conversion::.
  349.  
  350.     `(8489 20284)'
  351.           was last modified on Aug 19 00:09.
  352.  
  353.     `(8489 20285)'
  354.           last had its inode changed on Aug 19 00:09.
  355.  
  356.     `14906'
  357.           is 14906 characters long.
  358.  
  359.     `"-rw-rw-rw-"'
  360.           has a mode of read and write access for the owner, group, and
  361.           world.
  362.  
  363.     `nil'
  364.           would retain the same GID if it were recreated.
  365.  
  366.     `129500'
  367.           has an inode number of 129500.
  368.  
  369.     `-32252'
  370.           is on file system number -32252.
  371.  
  372. 
  373. File: lispref.info,  Node: Changing File Attributes,  Next: File Names,  Prev: Information about Files,  Up: Files
  374.  
  375. Changing File Names and Attributes
  376. ==================================
  377.  
  378.    The functions in this section rename, copy, delete, link, and set the
  379. modes of files.
  380.  
  381.    In the functions that have an argument NEWNAME, if a file by the
  382. name of NEWNAME already exists, the actions taken depend on the value
  383. of the argument OK-IF-ALREADY-EXISTS:
  384.  
  385.    * Signal a `file-already-exists' error if OK-IF-ALREADY-EXISTS is
  386.      `nil'.
  387.  
  388.    * Request confirmation if OK-IF-ALREADY-EXISTS is a number.
  389.  
  390.    * Replace the old file without confirmation if OK-IF-ALREADY-EXISTS
  391.      is any other value.
  392.  
  393.  - Command: add-name-to-file OLDNAME NEWNAME &optional
  394.           OK-IF-ALREADY-EXISTS
  395.      This function gives the file named OLDNAME the additional name
  396.      NEWNAME.  This means that NEWNAME becomes a new "hard link" to
  397.      OLDNAME.
  398.  
  399.      In the first part of the following example, we list two files,
  400.      `foo' and `foo3'.
  401.  
  402.           % ls -l fo*
  403.           -rw-rw-rw-  1 rms       29 Aug 18 20:32 foo
  404.           -rw-rw-rw-  1 rms       24 Aug 18 20:31 foo3
  405.  
  406.      Then we evaluate the form `(add-name-to-file "~/lewis/foo"
  407.      "~/lewis/foo2")'.  Again we list the files.  This shows two names,
  408.      `foo' and `foo2'.
  409.  
  410.           (add-name-to-file "~/lewis/foo1" "~/lewis/foo2")
  411.                => nil
  412.           
  413.           % ls -l fo*
  414.           -rw-rw-rw-  2 rms       29 Aug 18 20:32 foo
  415.           -rw-rw-rw-  2 rms       29 Aug 18 20:32 foo2
  416.           -rw-rw-rw-  1 rms       24 Aug 18 20:31 foo3
  417.  
  418.      Finally, we evaluate the following:
  419.  
  420.           (add-name-to-file "~/lewis/foo" "~/lewis/foo3" t)
  421.  
  422.      and list the files again.  Now there are three names for one file:
  423.      `foo', `foo2', and `foo3'.  The old contents of `foo3' are lost.
  424.  
  425.           (add-name-to-file "~/lewis/foo1" "~/lewis/foo3")
  426.                => nil
  427.           
  428.           % ls -l fo*
  429.           -rw-rw-rw-  3 rms       29 Aug 18 20:32 foo
  430.           -rw-rw-rw-  3 rms       29 Aug 18 20:32 foo2
  431.           -rw-rw-rw-  3 rms       29 Aug 18 20:32 foo3
  432.  
  433.      This function is meaningless on VMS, where multiple names for one
  434.      file are not allowed.
  435.  
  436.      See also `file-nlinks' in *Note File Attributes::.
  437.  
  438.  - Command: rename-file FILENAME NEWNAME &optional OK-IF-ALREADY-EXISTS
  439.      This command renames the file FILENAME as NEWNAME.
  440.  
  441.      If FILENAME has additional names aside from FILENAME, it continues
  442.      to have those names.  In fact, adding the name NEWNAME with
  443.      `add-name-to-file' and then deleting FILENAME has the same effect
  444.      as renaming, aside from momentary intermediate states.
  445.  
  446.      In an interactive call, this function prompts for FILENAME and
  447.      NEWNAME in the minibuffer; also, it requests confirmation if
  448.      NEWNAME already exists.
  449.  
  450.  - Command: copy-file OLDNAME NEWNAME &optional OK-IF-EXISTS TIME
  451.      This command copies the file OLDNAME to NEWNAME.  An error is
  452.      signaled if OLDNAME does not exist.
  453.  
  454.      If TIME is non-`nil', then this functions gives the new file the
  455.      same last-modified time that the old one has.  (This works on only
  456.      some operating systems.)
  457.  
  458.      In an interactive call, this function prompts for FILENAME and
  459.      NEWNAME in the minibuffer; also, it requests confirmation if
  460.      NEWNAME already exists.
  461.  
  462.  - Command: delete-file FILENAME
  463.      This command deletes the file FILENAME, like the shell command `rm
  464.      FILENAME'.  If the file has multiple names, it continues to exist
  465.      under the other names.
  466.  
  467.      A suitable kind of `file-error' error is signaled if the file does
  468.      not exist, or is not deletable.  (On Unix, a file is deletable if
  469.      its directory is writable.)
  470.  
  471.      See also `delete-directory' in *Note Create/Delete Dirs::.
  472.  
  473.  - Command: make-symbolic-link FILENAME NEWNAME &optional OK-IF-EXISTS
  474.      This command makes a symbolic link to FILENAME, named NEWNAME.
  475.      This is like the shell command `ln -s FILENAME NEWNAME'.
  476.  
  477.      In an interactive call, this function prompts for FILENAME and
  478.      NEWNAME in the minibuffer; also, it requests confirmation if
  479.      NEWNAME already exists.
  480.  
  481.  - Function: define-logical-name VARNAME STRING
  482.      This function defines the logical name NAME to have the value
  483.      STRING.  It is available only on VMS.
  484.  
  485.  - Function: set-file-modes FILENAME MODE
  486.      This function sets mode bits of FILENAME to MODE (which must be an
  487.      integer).  Only the low 12 bits of MODE are used.
  488.  
  489.  - Function: set-default-file-modes MODE
  490.      This function sets the default file protection for new files
  491.      created by XEmacs and its subprocesses.  Every file created with
  492.      XEmacs initially has this protection.  On Unix, the default
  493.      protection is the bitwise complement of the "umask" value.
  494.  
  495.      The argument MODE must be an integer.  Only the low 9 bits of MODE
  496.      are used.
  497.  
  498.      Saving a modified version of an existing file does not count as
  499.      creating the file; it does not change the file's mode, and does
  500.      not use the default file protection.
  501.  
  502.  - Function: default-file-modes
  503.      This function returns the current default protection value.
  504.  
  505.    On MS-DOS, there is no such thing as an "executable" file mode bit.
  506. So Emacs considers a file executable if its name ends in `.com', `.bat'
  507. or `.exe'.  This is reflected in the values returned by `file-modes'
  508. and `file-attributes'.
  509.  
  510. 
  511. File: lispref.info,  Node: File Names,  Next: Contents of Directories,  Prev: Changing File Attributes,  Up: Files
  512.  
  513. File Names
  514. ==========
  515.  
  516.    Files are generally referred to by their names, in XEmacs as
  517. elsewhere.  File names in XEmacs are represented as strings.  The
  518. functions that operate on a file all expect a file name argument.
  519.  
  520.    In addition to operating on files themselves, XEmacs Lisp programs
  521. often need to operate on the names; i.e., to take them apart and to use
  522. part of a name to construct related file names.  This section describes
  523. how to manipulate file names.
  524.  
  525.    The functions in this section do not actually access files, so they
  526. can operate on file names that do not refer to an existing file or
  527. directory.
  528.  
  529.    On VMS, all these functions understand both VMS file-name syntax and
  530. Unix syntax.  This is so that all the standard Lisp libraries can
  531. specify file names in Unix syntax and work properly on VMS without
  532. change.  On MS-DOS, these functions understand MS-DOS file-name syntax
  533. as well as Unix syntax.
  534.  
  535. * Menu:
  536.  
  537. * File Name Components::  The directory part of a file name, and the rest.
  538. * Directory Names::       A directory's name as a directory
  539.                             is different from its name as a file.
  540. * Relative File Names::   Some file names are relative to a current directory.
  541. * File Name Expansion::   Converting relative file names to absolute ones.
  542. * Unique File Names::     Generating names for temporary files.
  543. * File Name Completion::  Finding the completions for a given file name.
  544.  
  545. 
  546. File: lispref.info,  Node: File Name Components,  Next: Directory Names,  Up: File Names
  547.  
  548. File Name Components
  549. --------------------
  550.  
  551.    The operating system groups files into directories.  To specify a
  552. file, you must specify the directory and the file's name within that
  553. directory.  Therefore, XEmacs considers a file name as having two main
  554. parts: the "directory name" part, and the "nondirectory" part (or "file
  555. name within the directory").  Either part may be empty.  Concatenating
  556. these two parts reproduces the original file name.
  557.  
  558.    On Unix, the directory part is everything up to and including the
  559. last slash; the nondirectory part is the rest.  The rules in VMS syntax
  560. are complicated.
  561.  
  562.    For some purposes, the nondirectory part is further subdivided into
  563. the name proper and the "version number".  On Unix, only backup files
  564. have version numbers in their names; on VMS, every file has a version
  565. number, but most of the time the file name actually used in XEmacs
  566. omits the version number.  Version numbers are found mostly in
  567. directory lists.
  568.  
  569.  - Function: file-name-directory FILENAME
  570.      This function returns the directory part of FILENAME (or `nil' if
  571.      FILENAME does not include a directory part).  On Unix, the
  572.      function returns a string ending in a slash.  On VMS, it returns a
  573.      string ending in one of the three characters `:', `]', or `>'.
  574.  
  575.           (file-name-directory "lewis/foo")  ; Unix example
  576.                => "lewis/"
  577.           (file-name-directory "foo")        ; Unix example
  578.                => nil
  579.           (file-name-directory "[X]FOO.TMP") ; VMS example
  580.                => "[X]"
  581.  
  582.  - Function: file-name-nondirectory FILENAME
  583.      This function returns the nondirectory part of FILENAME.
  584.  
  585.           (file-name-nondirectory "lewis/foo")
  586.                => "foo"
  587.           (file-name-nondirectory "foo")
  588.                => "foo"
  589.           ;; The following example is accurate only on VMS.
  590.           (file-name-nondirectory "[X]FOO.TMP")
  591.                => "FOO.TMP"
  592.  
  593.  - Function: file-name-sans-versions FILENAME &optional
  594.           KEEP-BACKUP-VERSION
  595.      This function returns FILENAME without any file version numbers,
  596.      backup version numbers, or trailing tildes.
  597.  
  598.      If KEEP-BACKUP-VERSION is non-`nil', we do not remove backup
  599.      version numbers, only true file version numbers.
  600.  
  601.           (file-name-sans-versions "~rms/foo.~1~")
  602.                => "~rms/foo"
  603.           (file-name-sans-versions "~rms/foo~")
  604.                => "~rms/foo"
  605.           (file-name-sans-versions "~rms/foo")
  606.                => "~rms/foo"
  607.           ;; The following example applies to VMS only.
  608.           (file-name-sans-versions "foo;23")
  609.                => "foo"
  610.  
  611.  - Function: file-name-sans-extension FILENAME
  612.      This function returns FILENAME minus its "extension," if any.  The
  613.      extension, in a file name, is the part that starts with the last
  614.      `.' in the last name component.  For example,
  615.  
  616.           (file-name-sans-extension "foo.lose.c")
  617.                => "foo.lose"
  618.           (file-name-sans-extension "big.hack/foo")
  619.                => "big.hack/foo"
  620.  
  621. 
  622. File: lispref.info,  Node: Directory Names,  Next: Relative File Names,  Prev: File Name Components,  Up: File Names
  623.  
  624. Directory Names
  625. ---------------
  626.  
  627.    A "directory name" is the name of a directory.  A directory is a
  628. kind of file, and it has a file name, which is related to the directory
  629. name but not identical to it.  (This is not quite the same as the usual
  630. Unix terminology.)  These two different names for the same entity are
  631. related by a syntactic transformation.  On Unix, this is simple: a
  632. directory name ends in a slash, whereas the directory's name as a file
  633. lacks that slash.  On VMS, the relationship is more complicated.
  634.  
  635.    The difference between a directory name and its name as a file is
  636. subtle but crucial.  When an XEmacs variable or function argument is
  637. described as being a directory name, a file name of a directory is not
  638. acceptable.
  639.  
  640.    The following two functions convert between directory names and file
  641. names.  They do nothing special with environment variable substitutions
  642. such as `$HOME', and the constructs `~', and `..'.
  643.  
  644.  - Function: file-name-as-directory FILENAME
  645.      This function returns a string representing FILENAME in a form
  646.      that the operating system will interpret as the name of a
  647.      directory.  In Unix, this means appending a slash to the string.
  648.      On VMS, the function converts a string of the form `[X]Y.DIR.1' to
  649.      the form `[X.Y]'.
  650.  
  651.           (file-name-as-directory "~rms/lewis")
  652.                => "~rms/lewis/"
  653.  
  654.  - Function: directory-file-name DIRNAME
  655.      This function returns a string representing DIRNAME in a form that
  656.      the operating system will interpret as the name of a file.  On
  657.      Unix, this means removing a final slash from the string.  On VMS,
  658.      the function converts a string of the form `[X.Y]' to `[X]Y.DIR.1'.
  659.  
  660.           (directory-file-name "~lewis/")
  661.                => "~lewis"
  662.  
  663.    Directory name abbreviations are useful for directories that are
  664. normally accessed through symbolic links.  Sometimes the users recognize
  665. primarily the link's name as "the name" of the directory, and find it
  666. annoying to see the directory's "real" name.  If you define the link
  667. name as an abbreviation for the "real" name, XEmacs shows users the
  668. abbreviation instead.
  669.  
  670.    If you wish to convert a directory name to its abbreviation, use this
  671. function:
  672.  
  673.  - Function: abbreviate-file-name DIRNAME &optional HACK-HOMEDIR
  674.      This function applies abbreviations from `directory-abbrev-alist'
  675.      to its argument, and substitutes `~' for the user's home directory.
  676.  
  677.      If HACK-HOMEDIR is non-`nil', then this also substitutes `~' for
  678.      the user's home directory.
  679.  
  680.  
  681.  - Variable: directory-abbrev-alist
  682.      The variable `directory-abbrev-alist' contains an alist of
  683.      abbreviations to use for file directories.  Each element has the
  684.      form `(FROM . TO)', and says to replace FROM with TO when it
  685.      appears in a directory name.  The FROM string is actually a
  686.      regular expression; it should always start with `^'.  The function
  687.      `abbreviate-file-name' performs these substitutions.
  688.  
  689.      You can set this variable in `site-init.el' to describe the
  690.      abbreviations appropriate for your site.
  691.  
  692.      Here's an example, from a system on which file system `/home/fsf'
  693.      and so on are normally accessed through symbolic links named `/fsf'
  694.      and so on.
  695.  
  696.           (("^/home/fsf" . "/fsf")
  697.            ("^/home/gp" . "/gp")
  698.            ("^/home/gd" . "/gd"))
  699.  
  700. 
  701. File: lispref.info,  Node: Relative File Names,  Next: File Name Expansion,  Prev: Directory Names,  Up: File Names
  702.  
  703. Absolute and Relative File Names
  704. --------------------------------
  705.  
  706.    All the directories in the file system form a tree starting at the
  707. root directory.  A file name can specify all the directory names
  708. starting from the root of the tree; then it is called an "absolute"
  709. file name.  Or it can specify the position of the file in the tree
  710. relative to a default directory; then it is called a "relative" file
  711. name.  On Unix, an absolute file name starts with a slash or a tilde
  712. (`~'), and a relative one does not.  The rules on VMS are complicated.
  713.  
  714.  - Function: file-name-absolute-p FILENAME
  715.      This function returns `t' if file FILENAME is an absolute file
  716.      name, `nil' otherwise.  On VMS, this function understands both
  717.      Unix syntax and VMS syntax.
  718.  
  719.           (file-name-absolute-p "~rms/foo")
  720.                => t
  721.           (file-name-absolute-p "rms/foo")
  722.                => nil
  723.           (file-name-absolute-p "/user/rms/foo")
  724.                => t
  725.  
  726. 
  727. File: lispref.info,  Node: File Name Expansion,  Next: Unique File Names,  Prev: Relative File Names,  Up: File Names
  728.  
  729. Functions that Expand Filenames
  730. -------------------------------
  731.  
  732.    "Expansion" of a file name means converting a relative file name to
  733. an absolute one.  Since this is done relative to a default directory,
  734. you must specify the default directory name as well as the file name to
  735. be expanded.  Expansion also simplifies file names by eliminating
  736. redundancies such as `./' and `NAME/../'.
  737.  
  738.  - Function: expand-file-name FILENAME &optional DIRECTORY
  739.      This function converts FILENAME to an absolute file name.  If
  740.      DIRECTORY is supplied, it is the directory to start with if
  741.      FILENAME is relative.  (The value of DIRECTORY should itself be an
  742.      absolute directory name; it may start with `~'.)  Otherwise, the
  743.      current buffer's value of `default-directory' is used.  For
  744.      example:
  745.  
  746.           (expand-file-name "foo")
  747.                => "/xcssun/users/rms/lewis/foo"
  748.           (expand-file-name "../foo")
  749.                => "/xcssun/users/rms/foo"
  750.           (expand-file-name "foo" "/usr/spool/")
  751.                => "/usr/spool/foo"
  752.           (expand-file-name "$HOME/foo")
  753.                => "/xcssun/users/rms/lewis/$HOME/foo"
  754.  
  755.      Filenames containing `.' or `..' are simplified to their canonical
  756.      form:
  757.  
  758.           (expand-file-name "bar/../foo")
  759.                => "/xcssun/users/rms/lewis/foo"
  760.  
  761.      `~/' is expanded into the user's home directory.  A `/' or `~'
  762.      following a `/' is taken to be the start of an absolute file name
  763.      that overrides what precedes it, so everything before that `/' or
  764.      `~' is deleted.  For example:
  765.  
  766.           (expand-file-name
  767.            "/a1/gnu//usr/local/lib/emacs/etc/MACHINES")
  768.                => "/usr/local/lib/emacs/etc/MACHINES"
  769.           (expand-file-name "/a1/gnu/~/foo")
  770.                => "/xcssun/users/rms/foo"
  771.  
  772.      In both cases, `/a1/gnu/' is discarded because an absolute file
  773.      name follows it.
  774.  
  775.      Note that `expand-file-name' does *not* expand environment
  776.      variables; only `substitute-in-file-name' does that.
  777.  
  778.  - Function: file-relative-name FILENAME &optional DIRECTORY
  779.      This function does the inverse of expansion--it tries to return a
  780.      relative name that is equivalent to FILENAME when interpreted
  781.      relative to DIRECTORY.
  782.  
  783.      If DIRECTORY is `nil' or omitted, the value of `default-directory'
  784.      is used.
  785.  
  786.           (file-relative-name "/foo/bar" "/foo/")
  787.                => "bar")
  788.           (file-relative-name "/foo/bar" "/hack/")
  789.                => "../foo/bar")
  790.  
  791.  - Variable: default-directory
  792.      The value of this buffer-local variable is the default directory
  793.      for the current buffer.  It should be an absolute directory name;
  794.      it may start with `~'.  This variable is local in every buffer.
  795.  
  796.      `expand-file-name' uses the default directory when its second
  797.      argument is `nil'.
  798.  
  799.      On Unix systems, the value is always a string ending with a slash.
  800.  
  801.           default-directory
  802.                => "/user/lewis/manual/"
  803.  
  804.  - Function: substitute-in-file-name FILENAME
  805.      This function replaces environment variable references in FILENAME
  806.      with the environment variable values.  Following standard Unix
  807.      shell syntax, `$' is the prefix to substitute an environment
  808.      variable value.
  809.  
  810.      The environment variable name is the series of alphanumeric
  811.      characters (including underscores) that follow the `$'.  If the
  812.      character following the `$' is a `{', then the variable name is
  813.      everything up to the matching `}'.
  814.  
  815.      Here we assume that the environment variable `HOME', which holds
  816.      the user's home directory name, has value `/xcssun/users/rms'.
  817.  
  818.           (substitute-in-file-name "$HOME/foo")
  819.                => "/xcssun/users/rms/foo"
  820.  
  821.      After substitution, a `/' or `~' following a `/' is taken to be
  822.      the start of an absolute file name that overrides what precedes
  823.      it, so everything before that `/' or `~' is deleted.  For example:
  824.  
  825.           (substitute-in-file-name "bar/~/foo")
  826.                => "~/foo"
  827.           (substitute-in-file-name "/usr/local/$HOME/foo")
  828.                => "/xcssun/users/rms/foo"
  829.  
  830.      On VMS, `$' substitution is not done, so this function does nothing
  831.      on VMS except discard superfluous initial components as shown
  832.      above.
  833.  
  834. 
  835. File: lispref.info,  Node: Unique File Names,  Next: File Name Completion,  Prev: File Name Expansion,  Up: File Names
  836.  
  837. Generating Unique File Names
  838. ----------------------------
  839.  
  840.    Some programs need to write temporary files.  Here is the usual way
  841. to construct a name for such a file:
  842.  
  843.      (make-temp-name (concat "/tmp/" NAME-OF-APPLICATION))
  844.  
  845. Here we use the directory `/tmp/' because that is the standard place on
  846. Unix for temporary files.  The job of `make-temp-name' is to prevent
  847. two different users or two different processes from trying to use the
  848. same name.
  849.  
  850.  - Function: make-temp-name STRING
  851.      This function generates a string that can be used as a unique
  852.      name.  The name starts with STRING, and ends with a number that is
  853.      different in each XEmacs process.
  854.  
  855.           (make-temp-name "/tmp/foo")
  856.                => "/tmp/foo021304"
  857.  
  858.      To prevent conflicts among different libraries running in the same
  859.      XEmacs, each Lisp program that uses `make-temp-name' should have
  860.      its own STRING.  The number added to the end of the name
  861.      distinguishes between the same application running in different
  862.      XEmacs processes.
  863.  
  864. 
  865. File: lispref.info,  Node: File Name Completion,  Prev: Unique File Names,  Up: File Names
  866.  
  867. File Name Completion
  868. --------------------
  869.  
  870.    This section describes low-level subroutines for completing a file
  871. name.  For other completion functions, see *Note Completion::.
  872.  
  873.  - Function: file-name-all-completions PARTIAL-FILENAME DIRECTORY
  874.      This function returns a list of all possible completions for a file
  875.      whose name starts with PARTIAL-FILENAME in directory DIRECTORY.
  876.      The order of the completions is the order of the files in the
  877.      directory, which is unpredictable and conveys no useful
  878.      information.
  879.  
  880.      The argument PARTIAL-FILENAME must be a file name containing no
  881.      directory part and no slash.  The current buffer's default
  882.      directory is prepended to DIRECTORY, if DIRECTORY is not absolute.
  883.  
  884.      In the following example, suppose that the current default
  885.      directory, `~rms/lewis', has five files whose names begin with `f':
  886.      `foo', `file~', `file.c', `file.c.~1~', and `file.c.~2~'.
  887.  
  888.           (file-name-all-completions "f" "")
  889.                => ("foo" "file~" "file.c.~2~"
  890.                           "file.c.~1~" "file.c")
  891.           
  892.           (file-name-all-completions "fo" "")
  893.                => ("foo")
  894.  
  895.  - Function: file-name-completion FILENAME DIRECTORY
  896.      This function completes the file name FILENAME in directory
  897.      DIRECTORY.  It returns the longest prefix common to all file names
  898.      in directory DIRECTORY that start with FILENAME.
  899.  
  900.      If only one match exists and FILENAME matches it exactly, the
  901.      function returns `t'.  The function returns `nil' if directory
  902.      DIRECTORY contains no name starting with FILENAME.
  903.  
  904.      In the following example, suppose that the current default
  905.      directory has five files whose names begin with `f': `foo',
  906.      `file~', `file.c', `file.c.~1~', and `file.c.~2~'.
  907.  
  908.           (file-name-completion "fi" "")
  909.                => "file"
  910.           
  911.           (file-name-completion "file.c.~1" "")
  912.                => "file.c.~1~"
  913.           
  914.           (file-name-completion "file.c.~1~" "")
  915.                => t
  916.           
  917.           (file-name-completion "file.c.~3" "")
  918.                => nil
  919.  
  920.  - User Option: completion-ignored-extensions
  921.      `file-name-completion' usually ignores file names that end in any
  922.      string in this list.  It does not ignore them when all the possible
  923.      completions end in one of these suffixes or when a buffer showing
  924.      all possible completions is displayed.
  925.  
  926.      A typical value might look like this:
  927.  
  928.           completion-ignored-extensions
  929.                => (".o" ".elc" "~" ".dvi")
  930.  
  931. 
  932. File: lispref.info,  Node: Contents of Directories,  Next: Create/Delete Dirs,  Prev: File Names,  Up: Files
  933.  
  934. Contents of Directories
  935. =======================
  936.  
  937.    A directory is a kind of file that contains other files entered under
  938. various names.  Directories are a feature of the file system.
  939.  
  940.    XEmacs can list the names of the files in a directory as a Lisp list,
  941. or display the names in a buffer using the `ls' shell command.  In the
  942. latter case, it can optionally display information about each file,
  943. depending on the value of switches passed to the `ls' command.
  944.  
  945.  - Function: directory-files DIRECTORY &optional FULL-NAME MATCH-REGEXP
  946.           NOSORT FILES-ONLY
  947.      This function returns a list of the names of the files in the
  948.      directory DIRECTORY.  By default, the list is in alphabetical
  949.      order.
  950.  
  951.      If FULL-NAME is non-`nil', the function returns the files'
  952.      absolute file names.  Otherwise, it returns just the names
  953.      relative to the specified directory.
  954.  
  955.      If MATCH-REGEXP is non-`nil', this function returns only those
  956.      file names that contain that regular expression--the other file
  957.      names are discarded from the list.
  958.  
  959.      If NOSORT is non-`nil', `directory-files' does not sort the list,
  960.      so you get the file names in no particular order.  Use this if you
  961.      want the utmost possible speed and don't care what order the files
  962.      are processed in.  If the order of processing is visible to the
  963.      user, then the user will probably be happier if you do sort the
  964.      names.
  965.  
  966.      If FILES-ONLY is the symbol `t', then only the "files" in the
  967.      directory will be returned; subdirectories will be excluded.  If
  968.      FILES-ONLY is not `nil' and not `t', then only the subdirectories
  969.      will be returned.  Otherwise, if FILES-ONLY is `nil' (the default)
  970.      then both files and subdirectories will be returned.
  971.  
  972.           (directory-files "~lewis")
  973.                => ("#foo#" "#foo.el#" "." ".."
  974.                    "dired-mods.el" "files.texi"
  975.                    "files.texi.~1~")
  976.  
  977.      An error is signaled if DIRECTORY is not the name of a directory
  978.      that can be read.
  979.  
  980.  - Function: insert-directory FILE SWITCHES &optional WILDCARD
  981.           FULL-DIRECTORY-P
  982.      This function inserts (in the current buffer) a directory listing
  983.      for directory FILE, formatted with `ls' according to SWITCHES.  It
  984.      leaves point after the inserted text.
  985.  
  986.      The argument FILE may be either a directory name or a file
  987.      specification including wildcard characters.  If WILDCARD is
  988.      non-`nil', that means treat FILE as a file specification with
  989.      wildcards.
  990.  
  991.      If FULL-DIRECTORY-P is non-`nil', that means FILE is a directory
  992.      and switches do not contain `-d', so that the listing should show
  993.      the full contents of the directory.  (The `-d' option to `ls' says
  994.      to describe a directory itself rather than its contents.)
  995.  
  996.      This function works by running a directory listing program whose
  997.      name is in the variable `insert-directory-program'.  If WILDCARD is
  998.      non-`nil', it also runs the shell specified by `shell-file-name',
  999.      to expand the wildcards.
  1000.  
  1001.  - Variable: insert-directory-program
  1002.      This variable's value is the program to run to generate a
  1003.      directory listing for the function `insert-directory'.
  1004.  
  1005. 
  1006. File: lispref.info,  Node: Create/Delete Dirs,  Next: Magic File Names,  Prev: Contents of Directories,  Up: Files
  1007.  
  1008. Creating and Deleting Directories
  1009. =================================
  1010.  
  1011.    Most XEmacs Lisp file-manipulation functions get errors when used on
  1012. files that are directories.  For example, you cannot delete a directory
  1013. with `delete-file'.  These special functions exist to create and delete
  1014. directories.
  1015.  
  1016.  - Command: make-directory DIRNAME &optional PARENTS
  1017.      This function creates a directory named DIRNAME.  Interactively,
  1018.      the default choice of directory to create is the current default
  1019.      directory for file names.  That is useful when you have visited a
  1020.      file in a nonexistent directory.
  1021.  
  1022.      Non-interactively, optional argument PARENTS says whether to
  1023.      create parent directories if they don't exist. (Interactively, this
  1024.      always happens.)
  1025.  
  1026.  - Command: delete-directory DIRNAME
  1027.      This function deletes the directory named DIRNAME.  The function
  1028.      `delete-file' does not work for files that are directories; you
  1029.      must use `delete-directory' in that case.
  1030.  
  1031. 
  1032. File: lispref.info,  Node: Magic File Names,  Next: Partial Files,  Prev: Create/Delete Dirs,  Up: Files
  1033.  
  1034. Making Certain File Names "Magic"
  1035. =================================
  1036.  
  1037.    You can implement special handling for certain file names.  This is
  1038. called making those names "magic".  You must supply a regular
  1039. expression to define the class of names (all those that match the
  1040. regular expression), plus a handler that implements all the primitive
  1041. XEmacs file operations for file names that do match.
  1042.  
  1043.    The variable `file-name-handler-alist' holds a list of handlers,
  1044. together with regular expressions that determine when to apply each
  1045. handler.  Each element has this form:
  1046.  
  1047.      (REGEXP . HANDLER)
  1048.  
  1049. All the XEmacs primitives for file access and file name transformation
  1050. check the given file name against `file-name-handler-alist'.  If the
  1051. file name matches REGEXP, the primitives handle that file by calling
  1052. HANDLER.
  1053.  
  1054.    The first argument given to HANDLER is the name of the primitive;
  1055. the remaining arguments are the arguments that were passed to that
  1056. operation.  (The first of these arguments is typically the file name
  1057. itself.)  For example, if you do this:
  1058.  
  1059.      (file-exists-p FILENAME)
  1060.  
  1061. and FILENAME has handler HANDLER, then HANDLER is called like this:
  1062.  
  1063.      (funcall HANDLER 'file-exists-p FILENAME)
  1064.  
  1065.    Here are the operations that a magic file name handler gets to
  1066. handle:
  1067.  
  1068. `add-name-to-file', `copy-file', `delete-directory', `delete-file',
  1069. `diff-latest-backup-file', `directory-file-name', `directory-files',
  1070. `dired-compress-file', `dired-uncache', `expand-file-name',
  1071. `file-accessible-directory-p', `file-attributes', `file-directory-p',
  1072. `file-executable-p', `file-exists-p', `file-local-copy', `file-modes',
  1073. `file-name-all-completions', `file-name-as-directory',
  1074. `file-name-completion', `file-name-directory', `file-name-nondirectory',
  1075. `file-name-sans-versions', `file-newer-than-file-p', `file-readable-p',
  1076. `file-regular-p', `file-symlink-p', `file-truename', `file-writable-p',
  1077. `get-file-buffer', `insert-directory', `insert-file-contents', `load',
  1078. `make-directory', `make-symbolic-link', `rename-file', `set-file-modes',
  1079. `set-visited-file-modtime', `unhandled-file-name-directory',
  1080. `verify-visited-file-modtime', `write-region'.
  1081.  
  1082.    Handlers for `insert-file-contents' typically need to clear the
  1083. buffer's modified flag, with `(set-buffer-modified-p nil)', if the
  1084. VISIT argument is non-`nil'.  This also has the effect of unlocking the
  1085. buffer if it is locked.
  1086.  
  1087.    The handler function must handle all of the above operations, and
  1088. possibly others to be added in the future.  It need not implement all
  1089. these operations itself--when it has nothing special to do for a
  1090. certain operation, it can reinvoke the primitive, to handle the
  1091. operation "in the usual way".  It should always reinvoke the primitive
  1092. for an operation it does not recognize.  Here's one way to do this:
  1093.  
  1094.      (defun my-file-handler (operation &rest args)
  1095.        ;; First check for the specific operations
  1096.        ;; that we have special handling for.
  1097.        (cond ((eq operation 'insert-file-contents) ...)
  1098.              ((eq operation 'write-region) ...)
  1099.              ...
  1100.              ;; Handle any operation we don't know about.
  1101.              (t (let ((inhibit-file-name-handlers
  1102.                       (cons 'my-file-handler
  1103.                             (and (eq inhibit-file-name-operation operation)
  1104.                                  inhibit-file-name-handlers)))
  1105.                      (inhibit-file-name-operation operation))
  1106.                   (apply operation args)))))
  1107.  
  1108.    When a handler function decides to call the ordinary Emacs primitive
  1109. for the operation at hand, it needs to prevent the primitive from
  1110. calling the same handler once again, thus leading to an infinite
  1111. recursion.  The example above shows how to do this, with the variables
  1112. `inhibit-file-name-handlers' and `inhibit-file-name-operation'.  Be
  1113. careful to use them exactly as shown above; the details are crucial for
  1114. proper behavior in the case of multiple handlers, and for operations
  1115. that have two file names that may each have handlers.
  1116.  
  1117.  - Variable: inhibit-file-name-handlers
  1118.      This variable holds a list of handlers whose use is presently
  1119.      inhibited for a certain operation.
  1120.  
  1121.  - Variable: inhibit-file-name-operation
  1122.      The operation for which certain handlers are presently inhibited.
  1123.  
  1124.  - Function: find-file-name-handler FILE OPERATION
  1125.      This function returns the handler function for file name FILE, or
  1126.      `nil' if there is none.  The argument OPERATION should be the
  1127.      operation to be performed on the file--the value you will pass to
  1128.      the handler as its first argument when you call it.  The operation
  1129.      is needed for comparison with `inhibit-file-name-operation'.
  1130.  
  1131.  - Function: file-local-copy FILENAME
  1132.      This function copies file FILENAME to an ordinary non-magic file,
  1133.      if it isn't one already.
  1134.  
  1135.      If FILENAME specifies a "magic" file name, which programs outside
  1136.      Emacs cannot directly read or write, this copies the contents to
  1137.      an ordinary file and returns that file's name.
  1138.  
  1139.      If FILENAME is an ordinary file name, not magic, then this function
  1140.      does nothing and returns `nil'.
  1141.  
  1142.  - Function: unhandled-file-name-directory FILENAME
  1143.      This function returns the name of a directory that is not magic.
  1144.      It uses the directory part of FILENAME if that is not magic.
  1145.      Otherwise, it asks the handler what to do.
  1146.  
  1147.      This is useful for running a subprocess; every subprocess must
  1148.      have a non-magic directory to serve as its current directory, and
  1149.      this function is a good way to come up with one.
  1150.  
  1151. 
  1152. File: lispref.info,  Node: Partial Files,  Next: Format Conversion,  Prev: Magic File Names,  Up: Files
  1153.  
  1154. Partial Files
  1155. =============
  1156.  
  1157. * Menu:
  1158.  
  1159. * Intro to Partial Files::
  1160. * Creating a Partial File::
  1161. * Detached Partial Files::
  1162.  
  1163. 
  1164. File: lispref.info,  Node: Intro to Partial Files,  Next: Creating a Partial File,  Up: Partial Files
  1165.  
  1166. Intro to Partial Files
  1167. ----------------------
  1168.  
  1169.    A "partial file" is a section of a buffer (called the "master
  1170. buffer") that is placed in its own buffer and treated as its own file.
  1171. Changes made to the partial file are not reflected in the master buffer
  1172. until the partial file is "saved" using the standard buffer save
  1173. commands.  Partial files can be "reverted" (from the master buffer)
  1174. just like normal files.  When a file part is active on a master buffer,
  1175. that section of the master buffer is marked as read-only.  Two file
  1176. parts on the same master buffer are not allowed to overlap.  Partial
  1177. file buffers are indicated by the words `File Part' in the modeline.
  1178.  
  1179.    The master buffer knows about all the partial files that are active
  1180. on it, and thus killing or reverting the master buffer will be handled
  1181. properly.  When the master buffer is saved, if there are any unsaved
  1182. partial files active on it then the user will be given the opportunity
  1183. to first save these files.
  1184.  
  1185.    When a partial file buffer is first modified, the master buffer is
  1186. automatically marked as modified so that saving the master buffer will
  1187. work correctly.
  1188.  
  1189. 
  1190. File: lispref.info,  Node: Creating a Partial File,  Next: Detached Partial Files,  Prev: Intro to Partial Files,  Up: Partial Files
  1191.  
  1192. Creating a Partial File
  1193. -----------------------
  1194.  
  1195.  - Function: make-file-part &optional START END NAME BUFFER
  1196.      Make a file part on buffer BUFFER out of the region.  Call it
  1197.      NAME.  This command creates a new buffer containing the contents
  1198.      of the region and marks the buffer as referring to the specified
  1199.      buffer, called the "master buffer".  When the file-part buffer is
  1200.      saved, its changes are integrated back into the master buffer.
  1201.      When the master buffer is deleted, all file parts are deleted with
  1202.      it.
  1203.  
  1204.      When called from a function, expects four arguments, START, END,
  1205.      NAME, and BUFFER, all of which are optional and default to the
  1206.      beginning of BUFFER, the end of BUFFER, a name generated from
  1207.      BUFFER name, and the current buffer, respectively.
  1208.  
  1209. 
  1210. File: lispref.info,  Node: Detached Partial Files,  Prev: Creating a Partial File,  Up: Partial Files
  1211.  
  1212. Detached Partial Files
  1213. ----------------------
  1214.  
  1215.    Every partial file has an extent in the master buffer associated
  1216. with it (called the "master extent"), marking where in the master
  1217. buffer the partial file begins and ends.  If the text in master buffer
  1218. that is contained by the extent is deleted, then the extent becomes
  1219. "detached", meaning that it no longer refers to a specific region of
  1220. the master buffer.  This can happen either when the text is deleted
  1221. directly or when the master buffer is reverted.  Neither of these should
  1222. happen in normal usage because the master buffer should generally not be
  1223. edited directly.
  1224.  
  1225.    Before doing any operation that references a partial file's master
  1226. extent, XEmacs checks to make sure that the extent is not detached.  If
  1227. this is the case, XEmacs warns the user of this and the master extent is
  1228. deleted out of the master buffer, disconnecting the file part.  The file
  1229. part's filename is cleared and thus must be explicitly specified if the
  1230. detached file part is to be saved.
  1231.  
  1232.